// This will avoid problems if the VariableHolder is not yet initialized.
if (isnil "d_mission_functions_compiled") then {
	call compile PreProcessFileLineNumbers "missions\mission_functions.sqf";
	call compile PreProcessFileLineNumbers "missions\mission_tools.sqf";
	call compile PreProcessFileLineNumbers "missions\mission_reinforcement_functions.sqf";
	call compile PreProcessFileLineNumbers "missions\mission_airsupport.sqf";
	// This has to be initialized only one time
	DM_AI_VEC_EJECT = -8977;
	DM_AI_VEC_EMBARK = -8978;
	DM_AI_VEC = objNull;
	[[0,0,0], [0, 0, 0, false], ["NONE", "PRESENT", true], ["vehicle player != player", Format["DM_AI_VEC = vehicle player; if (DM_AI_VEC_EJECT == -8977) then {DM_AI_VEC_EJECT = DM_AI_VEC addAction ['%1' call XGreyText, 'missions\mission_eject_ai.sqf',[],-10,false,true,'','(({!isplayer _x} count (crew DM_AI_VEC)) > 0) && (((DM_AI_VEC) call XfGetHeight) <= 5) && (speed (DM_AI_VEC) <= 1)']}", localize "STR_MF_EJECT_AI"], "if (DM_AI_VEC_EJECT != -8977) then {DM_AI_VEC removeAction DM_AI_VEC_EJECT;DM_AI_VEC_EJECT = -8977}"]] call XfCreateTrigger;
	[[0,0,0], [0, 0, 0, false], ["NONE", "PRESENT", true], ["vehicle player != player", Format["DM_AI_VEC = vehicle player; if (DM_AI_VEC_EMBARK == -8978) then {DM_AI_VEC_EMBARK = DM_AI_VEC addAction ['%1' call XGreyText, 'missions\mission_embark_ai.sqf',[],-10,false,true,'','(player == (leader (group player))) && (({(!isplayer _x) && (vehicle _x == _x)} count (units group player)) > 0) && (((DM_AI_VEC) call XfGetHeight) <= 5) && (speed (DM_AI_VEC) <= 1)']}", localize "STR_MF_EMBARK_AI"], "if (DM_AI_VEC_EMBARK != -8978) then {DM_AI_VEC removeAction DM_AI_VEC_EMBARK;DM_AI_VEC_EMBARK = -8978}"]] call XfCreateTrigger;
};
waituntil{!(isNil "JIP_HINV") AND !(isNil "d_mission_functions_compiled")};
if (d_mission_debug_messages) then { diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"mission_init.sqf","Starting initialization!"]; };
if (isnil "TYR_FNCT_Compiled") then {
	call compile PreProcessFileLineNumbers "missions\TYR_FNCT_mission.sqf";
};
If (X_Client) then {
	nul = player call XfMissionInitializeObjects;
	player spawn XfMissionLoadPlayerActions;
	player spawn XfMissionLoadTasks;
	player spawn XfMissionLoadMarkers;
	player addEventHandler ["killed", XfMissionPlayerKilled];
};
If (X_Server) then {
	if (isnil "DM_Mission_Server_Initialized") then {
		DM_Mission_Server_Initialized = True;
		call XfMissionInitializeTeleporter;
		["current_mission_id",-1] call XNetSetJIP; 
		["available_missions",(["missions\m\"] call XfMissionListAvailableMissions)] call XNetSetJIP;
		// This will store all objects picked up by a player
		["mission_pickedup_objects",[]] call XNetSetJIP;
		if (d_mission_debug_messages) then { diag_log Format["JIPH available_missions %1",count(["available_missions",[]] call XNetGetJIP)]; };
		waituntil {sleep 0.05; !isnil "KRON_UPS_sharedist"};
		DM_Mission_UPSMON_Share_Dist = KRON_UPS_sharedist;
		
		call XfMissionLoadAllGroups;

		diag_log Format["     <[]>---- Mission Framework Loaded ----<[]>     "];
	};
};
